package org.example.entity;


import org.example.utils.TypeEnumUtil;

/**
 * 列属性
 **/

public class ColumnEntity {
    /**
     * 列名
     */
    private String columnName;

    /**
     * 列名类型
     */
    private String dataType;

    /**
     * 列名备注
     */
    private String comments;

    /**
     * 主键
     */
    private String columnKey;
    /**
     * auto_increment
     */
    private String extra;

    /**
     * 是否为空
     */
    private String isNull;


    public void setColumnName(String columnName) {
        this.columnName = columnName.toLowerCase();
    }


    //其他属性
    /**
     * java 类型
     */
    private String javaType;

    /**
     * 属性名称
     */
    private String attrName;

    public String getJavaType() {
        if (this.dataType != null)
            return TypeEnumUtil.valueOfJavaType(this.dataType).getJavaType();
        return null;
    }

    public String getAttrName() {
        StringBuilder sb = new StringBuilder();
        char[] c = getColumnName().toCharArray();

        //表名转换成属性名
        for (int i = 0; i < c.length; i++) {
            if ('_' == c[i]) {
                c[i + 1] = (char) (c[i + 1] - 32);
                continue;
            } else {
                sb.append(c[i]);
            }

        }
        return sb.toString();
    }

    public String getIsNull() {
        return isNull.toLowerCase();
    }

    public String getColumnName() {
        return columnName;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public String getColumnKey() {
        return columnKey;
    }

    public void setColumnKey(String columnKey) {
        this.columnKey = columnKey;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public void setIsNull(String isNull) {
        this.isNull = isNull;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public void setAttrName(String attrName) {
        this.attrName = attrName;
    }

    @Override
    public String toString() {
        return "ColumnEntity{" +
                "columnName='" + columnName + '\'' +
                ", dataType='" + dataType + '\'' +
                ", comments='" + comments + '\'' +
                ", columnKey='" + columnKey + '\'' +
                ", extra='" + extra + '\'' +
                ", isNull='" + isNull + '\'' +
                ", javaType='" + javaType + '\'' +
                ", attrName='" + attrName + '\'' +
                '}';
    }
}
